package tvs;

import java.util.ArrayList;
import java.util.List;

public class PlayerList {

	private List<Player> playerList;
	
	public PlayerList()
	{
		playerList = new ArrayList<Player>();
		//PlayerList.addPlayer(new Player("http://localhost:8080", "Shivesh"));
		
	}
	
	public boolean listDoesntContains(String playername)
	{
		boolean listDoesntContain = true;
		for(Player p : LobbyService.playerList.getList())
		{
			if(p.getName().equals(playername))
			{
				listDoesntContain = false;
			}
		}
		return listDoesntContain;
	}
	
	public void addPlayer(Player playerObj)
	{
		/*
		for(Player player : playerList)
		{
			if(player.getName() == playerObj.getName())
			{
				playerObj = new Player(playerObj.getIP(), playerObj.getName()+"(1)", playerObj.getWins(), playerObj.getLosses());
				addPlayer(playerObj);
				break;
			}
		}
		*/
		playerList.add(playerObj);
	}
	
	public void removePlayer(Player playerObj)
	{
		removePlayer(playerObj.getName());
	}
	
	public void removePlayer(String name)
	{
		for(Player player : playerList)
		{
			if(player.getName().equals(name))
			{
				playerList.remove(playerList.indexOf(player));
				break;
			}
		}
	}
	
	public Player getPlayer(String username)
	{
		for(Player player : playerList)
		{
			if(player.getName().equals(username))
			{
				return player;
			}
		}
		return null;
	}
	
	public List<Player> getList()
	{
		return playerList;
	}
	
}
